#函数式编程
#面向对象编程
# class Foo(object):
#     def func(self):
#         print("类方法")
# #实例化对象
# my_obj = Foo()
# my_obj.func()

#用户信息
# class UserInfo:
#     def __init__(self, name, pwd,age):
#         self.name = name
#         self.password=pwd
#         self.age=age
# def run():
#     user_object_list=[]
#     #用户注册
#     while True:
#         user=input("用户名：")
#         if user.upper()=='Q':
#             break
#         pwd=input("密码:")
#         age=input("年龄：")
#         user_object=UserInfo(user,pwd,age)
#         user_object_list.append(user_object)
#
#     for each in user_object_list:
#         print(each.name,":",each.password,",",each.age,"岁")
# run()

#对数据进行分页展示
# user_list=["用户-{}".format(i) for i in range(1,2000)]
#分页展示
# while True:
#     page=int(input("请输入页码："))
#     start_index=(page-1)*10
#     end_index=page*10
#     page_data_list=user_list[start_index:end_index]
#     for data in page_data_list:
#         print(data)
# class Pagination:
#     def __init__(self, current_page, per_page_num=10):
#         self.per_page_num = per_page_num
#         if not current_page.isdecimal():
#             self.current_page = 1
#             return
#         current_page = int(current_page)
#         if current_page < 1:
#             self.current_page = 1
#             return
#         self.current_page = current_page
#     def start(self):
#         return (self.current_page - 1) * self.per_page_num
#     def end(self):
#         return self.current_page * self.per_page_num
# user_list=["用户-{}".format(i) for i in range(1,3000)]
# while True:
#     page=input("请输入页码：")
#     pg_object=Pagination(page,20)
#     page_data_list=user_list[pg_object.start():pg_object.end()]
#     for data in page_data_list:
#         print(data)
# class Police:
#     """警察"""
#     def __init__(self, name, role):
#         self.name = name
#         self.role = role
#         if role == "队员":
#             self.hit_points = 200
#         else:
#             self.hit_points = 500
#     def show_status(self):
#         """ 查看警察状态 """
#         message = "警察{}的生命值为:{}".format(self.name, self.hit_points)
#         print(message)
#     def bomb(self, terrorist_list):
#         """ 投炸弹，炸掉恐怖分子 """
#         for terrorist in terrorist_list:
#             terrorist.blood -= 200
#             terrorist.show_status()

# class Terrorist:
#     """ 恐怖分子 """
#     def __init__(self, name, blood=300):
#         self.name = name
#         self.blood = blood
#     def shoot(self, police_object):
#         """ 开枪射击某个警察 """
#         police_object.hit_points -= 5
#         police_object.show_status()
#         self.blood -= 2
#     def strafe(self, police_object_list):
#         """ 扫射某些警察 """
#         for police_object in police_object_list:
#             police_object.hit_points -= 8
#             police_object.show_status()
#     def show_status(self):
#         """ 查看恐怖分子状态 """
#         message = "恐怖分子{}的血量值为:{}".format(self.name, self.blood)
#         print(message)
#
# def run():
#     # 1.创建3个警察
#     p1 = Police("小峰", "队员")
#     p2 = Police("苑昊", "队员")
#     p3 = Police("于超", "队长")
#     # 2.创建2个匪徒
#     t1 = Terrorist("alex")
#     t2 = Terrorist("eric")
#     # alex匪徒射击于超警察
#     t1.shoot(p3)
#     # alex扫射
#     t1.strafe([p1, p2, p3])
#     # eric射击苑昊
#     t2.shoot(p2)
#     # 小峰炸了那群匪徒王八蛋
#     p1.bomb([t1, t2])
#     # 小峰又炸了一次alex
#     p1.bomb([t1])
# if __name__ == '__main__':
#     run()
#

# class Email(object):
#     def send(self):
#         print("发邮件")
# class Message(object):
#     def send(self):
#         print("发短信")
# def func(arg):
#     v1 = arg.send()  # 浅拷贝
#
# v1 = Email()
# func(v1)
# v2 = Message()
# func(v2)

# v1=str()
# print(v1)
# data=v1.upper()
# print(data)
# class Person:
#     def fun1(self):
#         print("Person.fun1")
#
# class Student(Person):
#     def fun2(self):
#         return self.__class__.__base__.__name__
#
# o1=Student()
# data=o1.fun2()
# print(data)

# class Person(object):
#     country = "中国"
#
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
# print(Person.country) # 中国
#
# p1 = Person("小峰",20)
# print(p1.name) # 小峰
# print(p1.age) # 20
# print(p1.country) # 中国
#
# p1.name = "root"     # 在对象p1中讲name重置为root
# p1.num = 19          # 在对象p1中新增实例变量 num=19
# p1.country = "china" # 在对象p1中新增实例变量 country="china"
#
# print(p1.country)   # china
# print(Person.country) # 中国
# Person.country="china"
# print(Person.country) #china

# class Base(object):
#     country = "中国"
# class Person(Base):
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#     def show(self):
#         message = "{}-{}-{}".format(Person.country, self.name, self.age)
#         # message = "{}-{}-{}".format(self.country, self.name, self.age)
#         print(message)
# # 读
# print(Base.country) # 中国
# print(Person.country) # 中国
#
# obj = Person("小峰",19)
# print(obj.country) # 中国
#
# # 写
# Base.country = "china"
# Person.country = "泰国"
# obj.country = "日本"
# print(obj.country)  #日本
# print(Person.country) #泰国
# print(Base.country)  #china
# class Parent(object):
#     x = 1
# class Child1(Parent):
#     pass
# class Child2(Parent):
#     pass
#
# print(Parent.x, Child1.x, Child2.x) # 1 1 1
# Child1.x = 2
# print(Parent.x, Child1.x, Child2.x) # 1 2 1
# Parent.x = 3
# print(Parent.x, Child1.x, Child2.x) # 3 2 3

# class Foo(object):
#     def __init__(self, name, age):#初始化方法
#         self.name = name
#         self.age = age
#     def f1(self):
#         print("绑定方法", self.name)
#     @classmethod
#     def f2(cls):
#         print("类方法", cls)
#     @staticmethod
#     def f3():
#         print("静态方法")
#
# # 绑定方法（对象）
# obj = Foo("小峰", 20)
# obj.f1()
# Foo.f1(obj)
#
# # 类方法
# Foo.f2()  # cls就是当前调用这个方法的类。（类）
# obj.f2()  # cls就是当前调用这个方法的对象的类。
#
# # 静态方法
# Foo.f3()  # 类执行执行方法（类）
# obj.f3()  # 对象执行执行方法

# class Foo(object):
#     def __init__(self, name):
#         self.name = name
#     def f1(self):
#         return 123
#     @property
#     def f2(self):
#         return 123
#
# obj = Foo("小峰")
#
# v1 = obj.f1()
# print(v1)
#
# v2 = obj.f2 #v2 = obj.f2()
# print(v2)
# class C(object):
#     def __init__(self):
#         self.value=0
#     @property
#     def x(self):
#         return self.value
#
#     @x.setter
#     def x(self, value):
#         self.value = value
#
#     @x.deleter
#     def x(self):
#         self.value=0
#
# obj = C()
# obj.x
# obj.x = 123
# print(obj.x)  #123
# del obj.x
# print(obj.x)  #0
# class C(object):
#     def __init__(self):
#         self.value=0
#     def getx(self):
#         return self.value
#     def setx(self, value):
#         self.value = value
#     def delx(self):
#         self.value=0
#     x = property(getx, setx, delx, "I'm the 'x' property.")
#
# obj = C()
# obj.x
# obj.x = 123
# print(obj.x)  #123
# del obj.x
# print(obj.x)  #0


# class Foo(object):
#
#     def __init__(self, name, age):
#         self.__name = name
#         self.age = age
#
#     def get_data(self):
#         return self.__name
#     def get_age(self):
#         return self.age
#
#     def get_age1(self):
#         print("公有的get_age1")
#     def __get_data1(self):
#         print("私有的__get_data1方法")
#     def proxy(self):
#         print("公有的proxy")
#         self.__get_data1()
#
# #成员的访问
# obj = Foo("小峰", 123)
# # 公有成员
# print(obj.age)
# v1 = obj.get_age()
# print(v1)
# # 私有成员
# # print(obj.__name) # 错误，由于是私有成员，只能在类中进行使用。
# v2 = obj.get_data()
# print(v2)
#
# #方法的访问
# o1 = Foo("xiaofeng",10)
# o1.get_age1()
# # o1.__get_data1()   #私有方法只能在类内部进行访问
# o1.proxy()
# class Foo(object):
#
#     def __init__(self, name, age):
#         self.__name = name
#         self.age = age
#
#     @property
#     def __get_age(self):
#         print("公有的get_age")
#         return self.age
#
#     @property
#     def proxy(self):
#         print("公有的proxy")
#         return self.__name
#
#
# obj = Foo("xiaowu", 18)
# v1 = obj.proxy
# print(v1)
# # v2=obj.__get_age   #私有属性，只能在类内部进行访问
# # print(v2)
# class Base(object):
#     def __data(self):
#         print("base.__data")
#     def num(self):
#         print("base.num")
#
# class Foo(Base):
#     def func1(self):
#         self.num()
#     def func2(self):
#         self.__data()  # 不允许执行父类中的私有方法
#
# obj = Foo()
# obj.func1()
# #obj.func2() #会报错，子类不继承父类的私有成员（变量、方法、属性）
# class Foo(object):
#     def __init__(self):
#         self.__num = 123
#         self.age = 19
#
#     def __msg(self):
#         print(1234)
#
# obj = Foo()
# #访问私有变量
# print(obj.age)
# #print(obj.__num())  #会报错
# print(obj._Foo__num)
# #访问私有方法
# # print(obj.__msg())  #会报错
# obj._Foo__msg()

# class Student(object):
#     """ 学生类 """
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#     def message(self):
#         data = "我是一名学生，我叫:{},我今年{}岁".format(self.name, self.age)
#         print(data)
#
# class Classes(object):
#     """ 班级类 """
#     def __init__(self, title):
#         self.title = title
#         self.student_list = []
#     def add_student(self, stu_object):
#         self.student_list.append(stu_object)
#     def add_students(self, stu_object_list):
#         for stu in stu_object_list:
#             self.add_student(stu)
# s1 = Student("小峰", 19)
# s2 = Student("小张", 19)
# s3 = Student("日天", 19)
#
# c1 = Classes("三年二班")
# c1.add_student(s1)
# c1.add_students([s2, s3])
#
# print(c1.title)
# print(c1.student_list) #这样打印出来的只是学生对应对象的存储地址
# for i in range(len(c1.student_list)):  #正确的遍历班级成员列表，并打印出学生的相关信息
#     print(c1.student_list[i].name, c1.student_list[i].age)


# class Student(object):
#     """ 学生类 """
#     def __init__(self, name, age, class_object):
#         self.name = name
#         self.age = age
#         self.class_object = class_object
#     def message(self):
#         data = "我是一名{}班的学生，我叫:{},我今年{}岁".format(self.class_object.title, self.name, self.age)
#         print(data)
#
# class Classes(object):
#     """ 班级类 """
#     def __init__(self, title, school_object):
#         self.title = title
#         self.school_object = school_object
#
# class School(object):
#     """ 学校类 """
#     def __init__(self, name):
#         self.name = name
# #实例化学校类
# s1 = School("北京校区")
# s2 = School("上海校区")
# #实例化班级类
# c1 = Classes("Python全栈", s1)
# c2 = Classes("Linux云计算", s2)
# user_object_list = [
#     Student("小峰", 19, c1),
#     Student("小王", 19, c1),
#     Student("小白", 19, c2)
# ]
# for obj in user_object_list:
#     print(obj.name, obj.class_object.title, obj.class_object.school_object.name)
# class Foo(object):
#     def __init__(self, name):
#         print("第二步：初始化对象，在空对象中创建数据")
#         self.name = name
#
#     def __new__(cls, *args, **kwargs):
#         print("第一步：先创建空对象并返回")
#         return object.__new__(cls)
#
# obj = Foo("小峰")
# class Foo(object):
#     def __call__(self, *args, **kwargs):
#         print("执行call方法")
#
# obj = Foo()
# obj()  # 当遇见 对象名（） 的时候就会自动执行call方法
# class Foo(object):
#     def __str__(self):
#         return "必须返回字符串"
#
# obj = Foo("xiaowang")
# #下面两个语句打印的结果是一样的，第一个是对第二个语句内部做了优化而已
# print(obj)
# print(str(obj))
# class Foo(object):
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
# obj = Foo("小峰",19)
# print(obj.__dict__)
# class Foo(object):
#
#     def __setitem__(self, key, value):
#        self.value = value
#        # print(key, value)
#     def __getitem__(self, value):
#         return self.value
#     def __delitem__(self,key):
#         self.value = None
#         return key
#
# obj = Foo()
# obj["feng"]=19
# print(obj.__dict__)
# print(obj["feng"])
# obj['feng'] = 21
# print(obj["feng"])
# del obj["feng"]
# print(obj["feng"])
# class Foo(object):
#     def __enter__(self):
#         print("进入了")
#         return 666
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         print("出去了")
#
# obj = Foo()
# with obj as data:
#     print(data)
# class Foo(object):
#     def __init__(self, name):
#         self.name = name
#
#     def __add__(self, other):
#         return "{}-{}".format(self.name, other.name)
#
#
# v1 = Foo("I")
# v2 = Foo("Love")
# # 对象+值，内部会去执行 对象.__add__方法，并将+后面的值当做参数传递过去。
# v3 = v1 + v2
# print(v3)
# v4 = Foo("you")
#
# v5=Foo(v3)+v4
# print(v5)
# 创建 迭代器类型 ：
# class IT(object):
#     def __init__(self):
#         self.counter = 0
#     def __iter__(self):
#         return self
#     def __next__(self):
#         self.counter += 1
#         if self.counter == 3:
#             raise StopIteration()
#         return self.counter
# # 根据类实例化创建一个迭代器对象：
# # obj1 = IT()
# # v1 = next(obj1)  # obj1.__next__()
# # print(v1)
# # v2 = next(obj1)
# # print(v2)
# # v3 = next(obj1) # 抛出异常，异常会在后面的内容中讲到
# # print(v3)
# obj2 = IT()
# for item in obj2:  # 首先会执行迭代器对象的__iter__方法并获取返回值，一直去反复的执行 next(对象)
#     print(item)
# 创建生成器函数
# def func():
#     yield 1
#     yield 2
#
# obj2 = func()
# for item in obj2:
#     print(item)
# class IT(object):
#     def __init__(self):
#         self.counter = 0
#     def __iter__(self):
#         return self
#     def __next__(self):
#         self.counter += 1
#         if self.counter == 3:
#             raise StopIteration()
#         return self.counter
# class  Foo(object):
#     def __iter__(self):
#         return IT()
# obj = Foo()         # 可迭代对象
# for item in obj:    # 循环可迭代对象时，内部先执行obj.__iter__并获取迭代器对象；不断地执行迭代器对象的next方法。
#     print(item)
# class IterRange(object):
#     def __init__(self, num):
#         self.num = num
#         self.counter = -1
#     def __iter__(self):
#         return self
#     def __next__(self):
#         self.counter += 1
#         if self.counter == self.num:
#             raise StopIteration()
#         return self.counter
# class Xrange(object):
#     def __init__(self, max_num):
#         self.max_num = max_num
#     def __iter__(self):
#         return IterRange(self.max_num)
#
#
# obj = Xrange(100)
# for item in obj:
#     print(item)
# class Xrange(object):
#     def __init__(self, max_num):
#         self.max_num = max_num
#     def __iter__(self):
#         counter = 0
#         while counter > self.max_num:
#             yield counter
#             counter += 1
# obj = Xrange(100)
# for item in obj:
#     print(item)

# class Xrange(object):
#     def __init__(self, max_num):
#         self.max_num = max_num
#
#     def __iter__(self):
#         counter = 0
#         while counter < self.max_num:
#             yield counter
#             counter += 1
# obj = Xrange(100)
# for item in obj:
#     print(item)
# from collections.abc import Iterator, Iterable
# #Iterator检查对象是否是迭代器;Iterable,检查对象是否可以被迭代。
# #所有的迭代器都是可迭代的，但并非所有的可迭代对象都是迭代器。
# v1 = [11, 22, 33]
# print(isinstance(v1, Iterator))  #false，判断是否是迭代器；判断依据是__iter__ 和 __next__。
# v2 = v1.__iter__()
# print(isinstance(v2, Iterator))  #True
# v1 = [11, 22, 33]
# print(isinstance(v1, Iterable))  #True，判断依据是是否有 __iter__且返回迭代器对象。
# v2 = v1.__iter__()
# print(isinstance(v2, Iterable))  #True，判断依据是是否有 __iter__且返回迭代器对象。
# for i in v1:
#     print(i)
# class C(object):
#     pass
# class B(object):
#     pass
# class A(B, C):
#     pass
# print( A.mro() )   # [<class '__main__.A'>,<class '__main__.B'>, <class '__main__.C'>, <class 'object'>]
# print( A.__mro__ ) # (<class '__main__.A'>, <class '__main__.B'>, <class '__main__.C'>, <class 'object'>)
# class IT(object):
#     def __init__(self):
#         self.count = 0
#     def __iter__(self):
#         return self
#     def __next__(self):
#         self.count += 1
#         if self.count == 3:
#             raise StopIteration
#         return self.count
# obj=IT()
# while True:
#     try:
#         i=next(obj)
#     except StopIteration as e:
#         print("数据获取完毕")
#         break
#     print(i)
def func():
    try:
        return 123
    except Exception as e:
        pass
    finally:
        print(666)

print(func())  #先执行finally，再执行return